// 嗯，体力活没错了
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n;
int g[N * N];
int par[N * N];
int siz[N * N];
struct edge {
  int u, v, w;
  bool operator<(const edge &x) const { return w < x.w; }
};
vector<edge> e;
void add(int i, int j, int ti, int tj) {
  int u = n * i + j;
  int v = n * ti + tj;
  int fall = abs(g[u] - g[v]);
  e.push_back({u, v, fall});
}
int find(int x) { return par[x] = x == par[x] ? x : find(par[x]); }
int main() {
  cin >> n;
  for (int i = 0; i <= n * n; ++i) {
    par[i] = i;
    siz[i] = 1;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) cin >> g[n * i + j];

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int ti = i + 1, tj = j;
      if (ti < n) add(i, j, ti, tj);
      ti--, tj++;
      if (tj < n) add(i, j, ti, tj);
    }
  }
  sort(e.begin(), e.end());
  int sel = 0, ans = -1;
  for (int i = 0; i < e.size(); ++i) {
    auto [u, v, w] = e[i];
    int fu = find(u), fv = find(v);
    if (fu == fv) continue;
    par[fu] = fv;
    siz[fv] += siz[fu];
    if (siz[fv] >= (n * n + 1) / 2) {
      ans = w;
      break;
    }
  }
  cout << ans << endl;
}
